package view.panel.item
{
	import flash.display.DisplayObject;
	import flash.display.Sprite;
	import flash.text.TextField;
	
	import global.Resource;
	
	import utils.TextTool;
	
	import view.components.RemoteImage;
	import view.components.SimpleLoading;
	import view.components.list.ITileListItem;
	
	public class ItemShop extends Sprite implements ITileListItem
	{
		private var _data:Object;
		private var _bg:DisplayObject;
		private var _imgBg:DisplayObject;
		private var itemImg:RemoteImage;
		private var title:TextField;
		private var describ:TextField;
		private var price:TextField;
		
		
		
		public function ItemShop()
		{
			super();
			this.mouseChildren = false;
			this.mouseEnabled = false;
			initBg();
			initTitle();
		}
		
		public function switchState(state:int):void
		{}
		
		private function initTitle():void
		{
			title = TextTool.getTextField(60,20,14,0xFFFFFF,false,true);
			title.x = _imgBg.x + _imgBg.width + 3;
			title.y = 15;
			addChild(title);
			
			describ = TextTool.getTextField(180,50,12,0xFFFFFF);
			describ.multiline = true;
			describ.wordWrap = true;
			describ.x = title.x;
			describ.y = 35;
			addChild(describ);
			
			price = TextTool.getTextField(100,20,12,0xFFFFFF);
			price.x = title.x + title.width;
			price.y = 17;
			addChild(price);
		}
		
		private function initBg():void
		{
			_bg = Resource.getShape("butBg2");
			_bg.width = 254;
			_bg.height = 84;
			addChild(_bg);
			
			_imgBg = Resource.getShape("itemBg");
			_imgBg.x = 15;
			_imgBg.y = 15;
			addChild(_imgBg);
			
			itemImg = new RemoteImage(_imgBg.width,_imgBg.height,null,false,true);
			itemImg.x = _imgBg.x;
			itemImg.y = _imgBg.y;
			addChild(itemImg);
		}
		
		
		public function get self():DisplayObject
		{
			return this;
		}
		
		public function update(data:Object):void
		{
			_data = data;
			
			title.text = data.@name;
			describ.text = data.@desc;
			price.text =  data.@price;
			itemImg.loadImg("resource/item/" + data.@itemId + ".png");
		}
		
		public function drawSelectBg():void
		{
		}
		
		public function drawOverBg():void
		{
		}
		
		public function drawOutBg():void
		{
		}
		
		public function get selected():Boolean
		{
			return false;
		}
		
		public function set selected(v:Boolean):void
		{
		}
		
		public function get data():Object
		{
			return _data;
		}
		
		public function destroy():void
		{
		}
		
		public function getInstance():ITileListItem
		{
			return new ItemShop();
		}
		
		private var _index:int = -1;
		
		public function get index():int
		{
			return _index;
		}
		
		public function set index(v:int):void
		{
			_index = v;
		}
	}
}